package car.manager;

import java.util.LinkedList;

public class UserProfile {

	private int id;
	private String name;
	private LinkedList<Garage> garages;
	private float money;
	private final float starting_money = 5000;
	private int experience;
	private final int starting_experience = 0;

	private static LinkedList<UserProfile> users = new LinkedList<UserProfile>();
	private static int current_user=-1;

	public UserProfile(String name) {
		super();
		//String verification is done here or previously?
		this.id= askId();
		this.name = StringVerification(name);
		this.garages = new LinkedList<Garage>();
		this.money = starting_money;
		this.experience = starting_experience;
		users.add(this);
		current_user = id;

	}

	
	public UserProfile(int id, String name, float money, int experience) {
		super();
		this.id = id;
		this.name = name;
		this.garages = garages;
		this.money = money;
		this.experience = experience;
		users.add(this);


	}


	public static void removeUserProfile(int id){
		users.remove(getUserProfile(id));

	}


	public static void loadUserProfile(int id){
		current_user=id;
	}


	public  static UserProfile getUserProfile(int id){
		int index = -1;
		for(UserProfile u:users){
			if(u.getId()==id)
				index=users.indexOf(u);
		}

		if(index!=-1)
			return users.get(index);
		return null;
	}

	private int askId() {
		if(!users.isEmpty())
			return users.getLast().getId()+1;
		else
			return 1;
	}


	public static UserProfile getCurrentUserProfile(){
		if(current_user!=-1)
		return getUserProfile(current_user);
		return null;

	}

	public static void setCurrentUserProfile(int id){

		 current_user = id;

	}

	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	public LinkedList<Garage> getGarages() {
		return garages;
	}


	public void setGarages(LinkedList<Garage> garages) {
		this.garages = garages;
	}


	public float getMoney() {
		return money;
	}


	public void setMoney(float money) {
		this.money = money;
	}


	public int getExperience() {
		return experience;
	}


	public void setExperience(int experience) {
		this.experience = experience;
	}


	public float getStarting_money() {
		return starting_money;
	}


	public int getStarting_experience() {
		return starting_experience;
	}


	private String StringVerification(String name2) {
		if (name2!=null)
			return name2;
		return "john doe";
	}

	public int getId() {
		return id;
	}


	public void setId(int id) {
		this.id = id;
	}

	public static LinkedList<UserProfile> getAllProfiles() {
		// TODO Auto-generated method stub
		return users;
	}

}
